#!/bin/sh
##################################################################

USERNAME=_trace2

INSTALL_LOCATION=/usr/local/sample-trace2-otel-collector
chown $USERNAME "$INSTALL_LOCATION"

## Since this script is run by the package manager (rather than from a command
## line) we lose the normal stdout/stderr.  So direct all stdout and stderr
## for the rest of the life of this process into a log file.

mkdir -p "$INSTALL_LOCATION/logs"
LOGFILE="$INSTALL_LOCATION/logs/install.txt"
exec >>$LOGFILE 2>&1

chown -R $USERNAME "$INSTALL_LOCATION/logs"

echo ""
echo ""
echo ""
echo "================================================================"
echo "postinstall: X_VER_X"
echo "================================================================"
echo ""
date

set -x

## Integrate with launchctl...
cp $INSTALL_LOCATION/com.git-ecosystem.sample-trace2-otel-collector.plist /Library/LaunchDaemons/

echo Attempting to start sample-trace2-otel-collector
$INSTALL_LOCATION/scripts/service_start
